package com.huika.renrench.control.more.activity;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huika.lib.ui.widget.dialog.MMAlert;
import com.huika.renrench.R;
import com.huika.renrench.control.common.base.BaseAct;
import com.huika.renrench.control.common.environment.SetEnvironmentActivity;
import com.huika.renrench.utils.PhoneUtil;
import com.huika.renrench.view.MMAlertDialog;
import com.huika.renrench.view.TitleBarHelper;

public class AsregardsActivity extends BaseAct implements OnClickListener{

	private LinearLayout lin_phone_tel;
	private LinearLayout lin_adds_map;
	private TextView text_rrc_version;
	
	private TitleBarHelper titlenar;
	
	/**环境切换*/
	private static final int SWITCH_VERSION_CLK_NUM = 5;
	private int mCount = 0;
	private long mPreClickTime = 0;
	
//	@Override
//	protected void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		
//	}

	@Override
	public void onClick(View v) {
		long now = 0;
		switch (v.getId()) {
		case R.id.lin_phone_tel:
//			PhoneUtil.TelCALL(this, "400-6136-358");
			getTel();
			break;
		case R.id.lin_adds_map:
			break;
		case R.id.im_icon:
			now = System.currentTimeMillis();
			if (now - mPreClickTime < 300) {
				mCount++;
			} else {
				mCount = 1;
			}
			mPreClickTime = now;
			break;
		case R.id.text_rrc_version:
			now = System.currentTimeMillis();
			if (mCount >= SWITCH_VERSION_CLK_NUM && now - mPreClickTime < 1000) {
				Intent intent = new Intent(AsregardsActivity.this, SetEnvironmentActivity.class);
				startActivity(intent);
			}
			break;
		}
	}
	
	private Dialog TelDialog;// 
	private void getTel(){
		if (TelDialog == null) {
			TelDialog = MMAlertDialog.createPrivateDialogExitDialog(this, R.string.user_tel_phneo, R.string.user_tel,
					new MMAlert.DialogOnItemClickListener() {

						@Override
						public void onItemClickListener(View v, int position) {
							int id = v.getId();
							switch (id) {
								case R.id.item_second:
									PhoneUtil.TelCALL(AsregardsActivity.this , "400-6136-358");
									break;
							}
						}
					});
		}
		TelDialog.show();
	}

	@Override
	public void setRootView() {
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.as_regards_activity);
		
		titlenar = new TitleBarHelper(this, R.string.common_index_my, -1, R.string.as_regards_lin);
		titlenar.setLeftMsg(R.string.common_index_my);
		
		lin_phone_tel = (LinearLayout) findViewById(R.id.lin_phone_tel);
		lin_adds_map = (LinearLayout) findViewById(R.id.lin_adds_map);
		findViewById(R.id.im_icon).setOnClickListener(this);
		text_rrc_version = (TextView) findViewById(R.id.text_rrc_version);
		
		try {
			text_rrc_version.setText("人人创 V"+ getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		
		lin_phone_tel.setOnClickListener(this);
		lin_adds_map.setOnClickListener(this);
		text_rrc_version.setOnClickListener(this);
	}
	
}
